/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.jili.ubert.clientapi;

import com.jili.ubert.clientapi.until.UnWorkException;
import com.jili.ubert.clientapi.until.AnswerHandler;
import com.jili.ubert.clientapi.until.AnswerMsgResult;
import com.jili.ubert.clientapi.until.AbstractWorker;
import com.jili.ubert.clientapi.provider.HistoryDataProvider;
import com.jili.ubert.code.CodeTool;
import com.jili.ubert.code.client2server.Login;
import com.jili.ubert.code.client2server.RequestPageData;
import com.jili.ubert.code.server2client.MsgResult;
import com.panemu.tiwulfx.common.TableData;
import com.jili.ubert.code.server2client.PageDataProto;
import com.jili.ubert.dao.DBOperation;
import com.jili.ubert.dao.OnDBDataAccpet;
import com.jili.ubert.dao.db.FundTransfer;
import com.jili.ubert.dao.db.IOPVAccount;
import com.jili.ubert.dao.db.PosDetail;
import com.jili.ubert.dao.recent.RecentClearingDayBook;
import com.jili.ubert.dao.recent.RecentClearingFundState;
import com.jili.ubert.dao.recent.RecentClearingPosDetail;
import com.jili.ubert.dao.recent.RecentTradeAlterOrder;
import com.jili.ubert.dao.recent.RecentTradeCancelOrder;
import com.jili.ubert.dao.recent.RecentTradeExecuteOrder;
import com.jili.ubert.dao.recent.RecentTradeNewOrder;
import com.jili.ubert.dao.recent.RecentTradeReportDetail;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
 *
 * @author ChengJili
 */
class HistoryDataClient implements HistoryDataProvider {

    private static final Log log = LogFactory.getLog(TradeClient.class);
    private final SessionBucket sessionBucket = new SessionBucket();
    private final HashMap<Integer, OnDBDataAccpet> dbdataacceptor = new HashMap<>();
    private final HistoryDataNettyClient client;
    private HistoryDataRequest request;
    private DataPool dataPool;
    public void setDataPool(DataPool datapool) {
        this.dataPool = datapool;
    }

    public void setRequest(HistoryDataRequest request) {
        this.request = request;
    }
    private AtomicInteger requstid = new AtomicInteger(0);
    private int getRequstID() {
        if (requstid.getAndIncrement() == Integer.MAX_VALUE) {
            requstid.getAndSet(Integer.MIN_VALUE);
        }
        return requstid.intValue();
    }

    public HistoryDataClient(String host, int port) {
        this.client = new HistoryDataNettyClient();
        MsgResult ret = client.Connect(host, port, false, false, this);
        if (!ret.getSuccess()) {
            throw new UnWorkException(ret.getWord());
        }
    }

    public HistoryDataClient() {
        this.client = new HistoryDataNettyClient();
    }

//        @Override
    public MsgResult Connect(String host, int port, boolean isSSL, boolean isZlib) {
        return client.Connect(host, port, isSSL, isZlib, this);
    }

//    @Override
    public int Login(Login login,AnswerHandler<MsgResult> handler) throws IOException {
        int id = getRequstID();
        AbstractWorker worker = new AnswerMsgResult();
        worker.setAnswerHandler(handler);
        this.sessionBucket.AcceptSession(id, worker);
        client.SendSYNCMsg(1, id, login.EnCode(login));
        return id;
    }

//    @Override
    public int UserLogin(Login login,AnswerHandler<MsgResult> handler) throws IOException {
        int id = getRequstID();
        AbstractWorker worker = new AnswerMsgResult();
        worker.setAnswerHandler(handler);
        this.sessionBucket.AcceptSession(id, worker);
        client.SendSYNCMsg(48, id, login.EnCode(login));
        return id;
    }

/*
    @Override
    public int QueryHistoryOrders(String accountCode, int maxNum, boolean sortDirect, AnswerHandler<TableData<RecentTradeNewOrder>> handler) throws IOException {
        RequestPageData rqt = new RequestPageData();
        rqt.setStartIndex(1);
        rqt.setMaxResult(maxNum);
        rqt.setSortedColumns(sortDirect);
        List<String> acclist = new ArrayList<>();
        acclist.add(accountCode);
        rqt.setFilteredColumns(acclist);
        return QueryHistoryOrders(rqt,handler);
    }

    @Override
    public int QueryHistoryOrders(RequestPageData rpd, AnswerHandler<TableData<RecentTradeNewOrder>> handler) throws IOException {
        int id = getRequstID();
        AbstractWorker worker = new AbstractWorker() {

            @Override
            public void Onhandler(MsgEntity msg) {
                PageDataProto data;
                try {
                    data = PageDataProto.DeCode(msg.getData());
                    TableData<RecentTradeNewOrder> data0 = new TableData<>();
                    data0.setCurrentPage(data.getCurrentPage());
                    data0.setMaxResult(data.getMaxNum());
                    data0.setTotalNum(data.getTotalNum());
                    List<RecentTradeNewOrder> poss = new ArrayList<>();
                    data.getDataList().stream().forEach((byte[] posb) -> {
                        try {
                            poss.add(RecentTradeNewOrder.DeCode(posb));
                        } catch (IOException ex) {
                            log.info("QueryHistoryOrders-getDataList fail decode:" + ex);
                        }
                    });
                    data0.setDataList(poss);
                    getAnswer().OnAnswer(data0);
                } catch (IOException ex) {
                    log.info("QueryHistoryOrders fail decode:" + ex);
                }
            }

        };
        worker.setAnswerHandler(handler);
        this.sessionBucket.AcceptSession(id, worker);
        client.SendSYNCMsg(22, id, RequestPageData.EnCode(rpd));
        return id;
    }

    @Override
    public int QueryHistoryCancelOrders(String accountCode, int maxNum, boolean sortDirect, AnswerHandler<TableData<RecentTradeCancelOrder>> handler) throws IOException {
        RequestPageData rqt = new RequestPageData();
        rqt.setStartIndex(1);
        rqt.setMaxResult(maxNum);
        rqt.setSortedColumns(sortDirect);
        List<String> acclist = new ArrayList<>();
        acclist.add(accountCode);
        rqt.setFilteredColumns(acclist);
        return QueryHistoryCancelOrders(rqt,handler);
    }

    @Override
    public int QueryHistoryCancelOrders(RequestPageData rpd, AnswerHandler<TableData<RecentTradeCancelOrder>> handler) throws IOException {
        int id = getRequstID();
        AbstractWorker worker = new AbstractWorker() {

            @Override
            public void Onhandler(MsgEntity msg) {
                PageDataProto data;
                try {
                    data = PageDataProto.DeCode(msg.getData());
                    TableData<RecentTradeCancelOrder> data0 = new TableData<>();
                    data0.setCurrentPage(data.getCurrentPage());
                    data0.setMaxResult(data.getMaxNum());
                    data0.setTotalNum(data.getTotalNum());
                    List<RecentTradeCancelOrder> poss = new ArrayList<>();
                    data.getDataList().stream().forEach((byte[] posb) -> {
                        try {
                            poss.add(RecentTradeCancelOrder.DeCode(posb));
                        } catch (IOException ex) {
                            log.info("QueryHistoryCancelOrders-getDataList fail decode:" + ex);
                        }
                    });
                    data0.setDataList(poss);
                    getAnswer().OnAnswer(data0);
                } catch (IOException ex) {
                    log.info("QueryHistoryCancelOrders fail decode:" + ex);
                }
            }

        };
        worker.setAnswerHandler(handler);
        this.sessionBucket.AcceptSession(id, worker);
        client.SendSYNCMsg(22, id, RequestPageData.EnCode(rpd));
        return id;
    }

    @Override
    public int QueryHistoryAlterOrders(String accountCode, int maxNum, boolean sortDirect, AnswerHandler<TableData<RecentTradeAlterOrder>> handler) throws IOException {
        RequestPageData rqt = new RequestPageData();
        rqt.setStartIndex(1);
        rqt.setMaxResult(maxNum);
        rqt.setSortedColumns(sortDirect);
        List<String> acclist = new ArrayList<>();
        acclist.add(accountCode);
        rqt.setFilteredColumns(acclist);
        return QueryHistoryAlterOrders(rqt,handler);
    }

    @Override
    public int QueryHistoryAlterOrders(RequestPageData rpd, AnswerHandler<TableData<RecentTradeAlterOrder>> handler) throws IOException {
        int id = getRequstID();
        AbstractWorker worker = new AbstractWorker() {

            @Override
            public void Onhandler(MsgEntity msg) {
                PageDataProto data;
                try {
                    data = PageDataProto.DeCode(msg.getData());
                    TableData<RecentTradeAlterOrder> data0 = new TableData<>();
                    data0.setCurrentPage(data.getCurrentPage());
                    data0.setMaxResult(data.getMaxNum());
                    data0.setTotalNum(data.getTotalNum());
                    List<RecentTradeAlterOrder> poss = new ArrayList<>();
                    data.getDataList().stream().forEach((byte[] posb) -> {
                        try {
                            poss.add(RecentTradeAlterOrder.DeCode(posb));
                        } catch (IOException ex) {
                            log.info("QueryHistoryAlterOrders-getDataList fail decode:" + ex);
                        }
                    });
                    data0.setDataList(poss);
                    getAnswer().OnAnswer(data0);
                } catch (IOException ex) {
                    log.info("QueryHistoryAlterOrders fail decode:" + ex);
                }
            }

        };
        worker.setAnswerHandler(handler);
        this.sessionBucket.AcceptSession(id, worker);
        client.SendSYNCMsg(22, id, RequestPageData.EnCode(rpd));
        return id;
    }

    @Override
    public int QueryHistoryOrderReports(String accountCode, int maxNum, boolean sortDirect, AnswerHandler<TableData<RecentTradeReportDetail>> handler) throws IOException {
        RequestPageData rqt = new RequestPageData();
        rqt.setStartIndex(1);
        rqt.setMaxResult(maxNum);
        rqt.setSortedColumns(sortDirect);
        List<String> acclist = new ArrayList<>();
        acclist.add(accountCode);
        rqt.setFilteredColumns(acclist);
        return QueryHistoryOrderReports(rqt,handler);
    }

    @Override
    public int QueryHistoryOrderReports(RequestPageData rpd, AnswerHandler<TableData<RecentTradeReportDetail>> handler) throws IOException {
        int id = getRequstID();
        AbstractWorker worker = new AbstractWorker() {

            @Override
            public void Onhandler(MsgEntity msg) {
                PageDataProto data;
                try {
                    data = PageDataProto.DeCode(msg.getData());
                    TableData<RecentTradeReportDetail> data0 = new TableData<>();
                    data0.setCurrentPage(data.getCurrentPage());
                    data0.setMaxResult(data.getMaxNum());
                    data0.setTotalNum(data.getTotalNum());
                    List<RecentTradeReportDetail> poss = new ArrayList<>();
                    data.getDataList().stream().forEach((byte[] posb) -> {
                        try {
                            poss.add(RecentTradeReportDetail.DeCode(posb));
                        } catch (IOException ex) {
                            log.info("QueryHistoryOrderReports-getDataList fail decode:" + ex);
                        }
                    });
                    data0.setDataList(poss);
                    getAnswer().OnAnswer(data0);
                } catch (IOException ex) {
                    log.info("QueryHistoryOrderReports fail decode:" + ex);
                }
            }

        };
        worker.setAnswerHandler(handler);
        this.sessionBucket.AcceptSession(id, worker);
        client.SendSYNCMsg(22, id, RequestPageData.EnCode(rpd));
        return id;
    }

    @Override
    public int QueryHistoryOrderExecteStatus(String accountCode, int maxNum, boolean sortDirect, AnswerHandler<TableData<RecentTradeExecuteOrder>> handler) throws IOException {
        RequestPageData rqt = new RequestPageData();
        rqt.setStartIndex(1);
        rqt.setMaxResult(maxNum);
        rqt.setSortedColumns(sortDirect);
        List<String> acclist = new ArrayList<>();
        acclist.add(accountCode);
        rqt.setFilteredColumns(acclist);
        return QueryHistoryOrderExecteStatus(rqt,handler);
    }

    @Override
    public int QueryHistoryOrderExecteStatus(RequestPageData rpd, AnswerHandler<TableData<RecentTradeExecuteOrder>> handler) throws IOException {
        int id = getRequstID();
        AbstractWorker worker = new AbstractWorker() {

            @Override
            public void Onhandler(MsgEntity msg) {
                PageDataProto data;
                try {
                    data = PageDataProto.DeCode(msg.getData());
                    TableData<RecentTradeExecuteOrder> data0 = new TableData<>();
                    data0.setCurrentPage(data.getCurrentPage());
                    data0.setMaxResult(data.getMaxNum());
                    data0.setTotalNum(data.getTotalNum());
                    List<RecentTradeExecuteOrder> poss = new ArrayList<>();
                    data.getDataList().stream().forEach((byte[] posb) -> {
                        try {
                            poss.add(RecentTradeExecuteOrder.DeCode(posb));
                        } catch (IOException ex) {
                            log.info("QueryHistoryOrderExecteStatus-getDataList fail decode:" + ex);
                        }
                    });
                    data0.setDataList(poss);
                    getAnswer().OnAnswer(data0);
                } catch (IOException ex) {
                    log.info("QueryHistoryOrderExecteStatus fail decode:" + ex);
                }
            }

        };
        worker.setAnswerHandler(handler);
        this.sessionBucket.AcceptSession(id, worker);
        client.SendSYNCMsg(22, id, RequestPageData.EnCode(rpd));
        return id;
    }

    @Override
    public int QueryHistoryPosList(String accountCode, int maxNum, boolean sortDirect, AnswerHandler<TableData<RecentClearingPosDetail>> handler) throws IOException {
        RequestPageData rqt = new RequestPageData();
        rqt.setStartIndex(1);
        rqt.setMaxResult(maxNum);
        rqt.setSortedColumns(sortDirect);
        List<String> acclist = new ArrayList<>();
        acclist.add(accountCode);
        rqt.setFilteredColumns(acclist);
        return QueryHistoryPosList(rqt,handler);
    }

    @Override
    public int QueryHistoryPosList(RequestPageData rpd, AnswerHandler<TableData<RecentClearingPosDetail>> handler) throws IOException {
        int id = getRequstID();
        AbstractWorker worker = new AbstractWorker() {

            @Override
            public void Onhandler(MsgEntity msg) {
                PageDataProto data;
                try {
                    data = PageDataProto.DeCode(msg.getData());
                    TableData<RecentClearingPosDetail> data0 = new TableData<>();
                    data0.setCurrentPage(data.getCurrentPage());
                    data0.setMaxResult(data.getMaxNum());
                    data0.setTotalNum(data.getTotalNum());
                    List<RecentClearingPosDetail> poss = new ArrayList<>();
                    data.getDataList().stream().forEach((byte[] posb) -> {
                        try {
                            poss.add(RecentClearingPosDetail.DeCode(posb));
                        } catch (IOException ex) {
                            log.info("QueryHistoryPosList-getDataList fail decode:" + ex);
                        }
                    });
                    data0.setDataList(poss);
                    getAnswer().OnAnswer(data0);
                } catch (IOException ex) {
                    log.info("QueryHistoryPosList fail decode:" + ex);
                }
            }

        };
        worker.setAnswerHandler(handler);
        this.sessionBucket.AcceptSession(id, worker);
        client.SendSYNCMsg(22, id, RequestPageData.EnCode(rpd));
        return id;
    }

    @Override
    public int QueryHistoryFundStatus(String accountCode, int maxNum, boolean sortDirect, AnswerHandler<TableData<RecentClearingFundState>> handler) throws IOException {
        RequestPageData rqt = new RequestPageData();
        rqt.setStartIndex(1);
        rqt.setMaxResult(maxNum);
        rqt.setSortedColumns(sortDirect);
        List<String> acclist = new ArrayList<>();
        acclist.add(accountCode);
        rqt.setFilteredColumns(acclist);
        return QueryHistoryFundStatus(rqt,handler);
    }

    @Override
    public int QueryHistoryFundStatus(RequestPageData rpd, AnswerHandler<TableData<RecentClearingFundState>> handler) throws IOException {
        int id = getRequstID();
        AbstractWorker worker = new AbstractWorker() {

            @Override
            public void Onhandler(MsgEntity msg) {
                PageDataProto data;
                try {
                    data = PageDataProto.DeCode(msg.getData());
                    TableData<RecentClearingFundState> data0 = new TableData<>();
                    data0.setCurrentPage(data.getCurrentPage());
                    data0.setMaxResult(data.getMaxNum());
                    data0.setTotalNum(data.getTotalNum());
                    List<RecentClearingFundState> poss = new ArrayList<>();
                    data.getDataList().stream().forEach((byte[] posb) -> {
                        try {
                            poss.add(RecentClearingFundState.DeCode(posb));
                        } catch (IOException ex) {
                            log.info("QueryHistoryFundStatus-getDataList fail decode:" + ex);
                        }
                    });
                    data0.setDataList(poss);
                    getAnswer().OnAnswer(data0);
                } catch (IOException ex) {
                    log.info("QueryHistoryFundStatus fail decode:" + ex);
                }
            }

        };
        worker.setAnswerHandler(handler);
        this.sessionBucket.AcceptSession(id, worker);
        client.SendSYNCMsg(22, id, RequestPageData.EnCode(rpd));
        return id;
    }

    @Override
    public int QueryHistoryClearingsDayBook(String accountCode, int maxNum, boolean sortDirect, AnswerHandler<TableData<RecentClearingDayBook>> handler) throws IOException {
        RequestPageData rqt = new RequestPageData();
        rqt.setStartIndex(1);
        rqt.setMaxResult(maxNum);
        rqt.setSortedColumns(sortDirect);
        List<String> acclist = new ArrayList<>();
        acclist.add(accountCode);
        rqt.setFilteredColumns(acclist);
        return QueryHistoryClearingsDayBook(rqt,handler);
    }

    @Override
    public int QueryHistoryClearingsDayBook(RequestPageData rpd, AnswerHandler<TableData<RecentClearingDayBook>> handler) throws IOException {
        int id = getRequstID();
        AbstractWorker worker = new AbstractWorker() {

            @Override
            public void Onhandler(MsgEntity msg) {
                PageDataProto data;
                try {
                    data = PageDataProto.DeCode(msg.getData());
                    TableData<RecentClearingDayBook> data0 = new TableData<>();
                    data0.setCurrentPage(data.getCurrentPage());
                    data0.setMaxResult(data.getMaxNum());
                    data0.setTotalNum(data.getTotalNum());
                    List<RecentClearingDayBook> poss = new ArrayList<>();
                    data.getDataList().stream().forEach((byte[] posb) -> {
                        try {
                            poss.add(RecentClearingDayBook.DeCode(posb));
                        } catch (IOException ex) {
                            log.info("QueryHistoryClearingsDayBook-getDataList fail decode:" + ex);
                        }
                    });
                    data0.setDataList(poss);
                    getAnswer().OnAnswer(data0);
                } catch (IOException ex) {
                    log.info("QueryHistoryClearingsDayBook fail decode:" + ex);
                }
            }

        };
        worker.setAnswerHandler(handler);
        this.sessionBucket.AcceptSession(id, worker);
        client.SendSYNCMsg(22, id, RequestPageData.EnCode(rpd));
        return id;
    }

    @Override
    public int QueryHistoryNetFund(String accountCode, int maxNum, boolean sortDirect, AnswerHandler<TableData<IOPVAccount>> handler) throws IOException {
        RequestPageData rqt = new RequestPageData();
        rqt.setStartIndex(1);
        rqt.setMaxResult(maxNum);
        rqt.setSortedColumns(sortDirect);
        List<String> acclist = new ArrayList<>();
        acclist.add(accountCode);
        rqt.setFilteredColumns(acclist);
        return QueryHistoryNetFund(rqt,handler);
    }

    @Override
    public int QueryHistoryNetFund(RequestPageData rpd, AnswerHandler<TableData<IOPVAccount>> handler) throws IOException {
        int id = getRequstID();
        AbstractWorker worker = new AbstractWorker() {

            @Override
            public void Onhandler(MsgEntity msg) {
                PageDataProto data;
                try {
                    data = PageDataProto.DeCode(msg.getData());
                    TableData<IOPVAccount> data0 = new TableData<>();
                    data0.setCurrentPage(data.getCurrentPage());
                    data0.setMaxResult(data.getMaxNum());
                    data0.setTotalNum(data.getTotalNum());
                    List<IOPVAccount> poss = new ArrayList<>();
                    data.getDataList().stream().forEach((byte[] posb) -> {
                        try {
                            poss.add(IOPVAccount.DeCode(posb));
                        } catch (IOException ex) {
                            log.info("QueryHistoryNetFund-getDataList fail decode:" + ex);
                        }
                    });
                    data0.setDataList(poss);
                    getAnswer().OnAnswer(data0);
                } catch (IOException ex) {
                    log.info("QueryHistoryNetFund fail decode:" + ex);
                }
            }

        };
        worker.setAnswerHandler(handler);
        this.sessionBucket.AcceptSession(id, worker);
        client.SendSYNCMsg(22, id, RequestPageData.EnCode(rpd));
        return id;
    }

    @Override
    public int QueryHistoryFundTransfer(String accountCode, int maxNum, boolean sortDirect, AnswerHandler<TableData<FundTransfer>> handler) throws IOException {
        RequestPageData rqt = new RequestPageData();
        rqt.setStartIndex(1);
        rqt.setMaxResult(maxNum);
        rqt.setSortedColumns(sortDirect);
        List<String> acclist = new ArrayList<>();
        acclist.add(accountCode);
        rqt.setFilteredColumns(acclist);
        return QueryHistoryFundTransfer(rqt,handler);
    }

    @Override
    public int QueryHistoryFundTransfer(RequestPageData rpd, AnswerHandler<TableData<FundTransfer>> handler) throws IOException {
        int id = getRequstID();
        AbstractWorker worker = new AbstractWorker() {

            @Override
            public void Onhandler(MsgEntity msg) {
                PageDataProto data;
                try {
                    data = PageDataProto.DeCode(msg.getData());
                    TableData<FundTransfer> data0 = new TableData<>();
                    data0.setCurrentPage(data.getCurrentPage());
                    data0.setMaxResult(data.getMaxNum());
                    data0.setTotalNum(data.getTotalNum());
                    List<FundTransfer> poss = new ArrayList<>();
                    data.getDataList().stream().forEach((byte[] posb) -> {
                        try {
                            poss.add(FundTransfer.DeCode(posb));
                        } catch (IOException ex) {
                            log.info("QueryHistoryFundTransfer-getDataList fail decode:" + ex);
                        }
                    });
                    data0.setDataList(poss);
                    getAnswer().OnAnswer(data0);
                } catch (IOException ex) {
                    log.info("QueryHistoryFundTransfer fail decode:" + ex);
                }
            }

        };
        worker.setAnswerHandler(handler);
        this.sessionBucket.AcceptSession(id, worker);
        client.SendSYNCMsg(22, id, RequestPageData.EnCode(rpd));
        return id;
    }

    @Override
    public int Select(DBTableName tablename, String key, AnswerHandler<TableData> handler) throws IOException {
        int id = getRequstID();
        AbstractWorker worker = new AbstractWorker() {

            @Override
            public void Onhandler(MsgEntity msg) {
                TableData data = new TableData();
                String str = CodeTool.BitToString(msg.getData());
                data = data.Decode(str);
                getAnswer().OnAnswer(data);
            }

        };
        worker.setAnswerHandler(handler);
        this.sessionBucket.AcceptSession(id, worker);
        DAOEntity dao = new DAOEntity();
        dao.setTableName(tablename);
        dao.setOperation(DBOperation.SELECT);
        dao.setData(CodeTool.StringToBit1(key));
        client.SendSYNCMsg(1000, id, DAOEntity.EnCode(dao));
        return id;
    }

    @Override
    public int HSQLSelect(String hsql, AnswerHandler<TableData> handler) throws IOException {
        int id = getRequstID();
        AbstractWorker worker = new AbstractWorker() {

            @Override
            public void Onhandler(MsgEntity msg) {
                TableData data = new TableData();
                String str = CodeTool.BitToString(msg.getData());
                data = data.Decode(str);
                getAnswer().OnAnswer(data);
            }

        };
        worker.setAnswerHandler(handler);
        this.sessionBucket.AcceptSession(id, worker);
        DAOEntity dao = new DAOEntity();
        dao.setTableName(DBTableName.SQL);
        dao.setOperation(DBOperation.SELECT);
        dao.setData(CodeTool.StringToBit1(hsql));
        this.client.SendSYNCMsg(1000, id, dao.EnCode(dao));
        return id;
    }

    @Override
    public int SQLSelect(String sql, AnswerHandler<TableData> handler) throws IOException {
        int id = getRequstID();
        AbstractWorker worker = new AbstractWorker() {

            @Override
            public void Onhandler(MsgEntity msg) {
                TableData data = new TableData();
                String str = CodeTool.BitToString(msg.getData());
                data = data.Decode(str);
                getAnswer().OnAnswer(data);
            }

        };
        worker.setAnswerHandler(handler);
        this.sessionBucket.AcceptSession(id, worker);
        DAOEntity dao = new DAOEntity();
        dao.setTableName(DBTableName.SQL);
        dao.setOperation(DBOperation.SELECT);
        dao.setData(CodeTool.StringToBit1(sql));
        this.client.SendSYNCMsg(1000, id, dao.EnCode(dao));
        return id;
    }
*/
    public void AccpetSessionAnswer(int id,MsgEntity msg) {
        this.sessionBucket.OnDealSession(id,msg);
    }

    @Override
    public int QueryHistoryOrders(String accountCode, int maxNum, boolean sortDirect, AnswerHandler<TableData<RecentTradeNewOrder>> handler) throws IOException {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public int QueryHistoryOrders(RequestPageData rpd, AnswerHandler<TableData<RecentTradeNewOrder>> handler) throws IOException {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public int QueryHistoryCancelOrders(String accountCode, int maxNum, boolean sortDirect, AnswerHandler<TableData<RecentTradeCancelOrder>> handler) throws IOException {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public int QueryHistoryCancelOrders(RequestPageData rpd, AnswerHandler<TableData<RecentTradeCancelOrder>> handler) throws IOException {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public int QueryHistoryAlterOrders(String accountCode, int maxNum, boolean sortDirect, AnswerHandler<TableData<RecentTradeAlterOrder>> handler) throws IOException {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public int QueryHistoryAlterOrders(RequestPageData rpd, AnswerHandler<TableData<RecentTradeAlterOrder>> handler) throws IOException {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public int QueryHistoryOrderReports(String accountCode, int maxNum, boolean sortDirect, AnswerHandler<TableData<RecentTradeReportDetail>> handler) throws IOException {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public int QueryHistoryOrderReports(RequestPageData rpd, AnswerHandler<TableData<RecentTradeReportDetail>> handler) throws IOException {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public int QueryHistoryOrderExecteStatus(String accountCode, int maxNum, boolean sortDirect, AnswerHandler<TableData<RecentTradeExecuteOrder>> handler) throws IOException {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public int QueryHistoryOrderExecteStatus(RequestPageData rpd, AnswerHandler<TableData<RecentTradeExecuteOrder>> handler) throws IOException {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public int QueryHistoryPosList(String accountCode, int maxNum, boolean sortDirect, AnswerHandler<TableData<RecentClearingPosDetail>> handler) throws IOException {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public int QueryHistoryPosList(RequestPageData rpd, AnswerHandler<TableData<RecentClearingPosDetail>> handler) throws IOException {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public int QueryHistoryFundStatus(String accountCode, int maxNum, boolean sortDirect, AnswerHandler<TableData<RecentClearingFundState>> handler) throws IOException {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public int QueryHistoryFundStatus(RequestPageData rpd, AnswerHandler<TableData<RecentClearingFundState>> handler) throws IOException {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public int QueryHistoryClearingsDayBook(String accountCode, int maxNum, boolean sortDirect, AnswerHandler<TableData<RecentClearingDayBook>> handler) throws IOException {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public int QueryHistoryClearingsDayBook(RequestPageData rpd, AnswerHandler<TableData<RecentClearingDayBook>> handler) throws IOException {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public int QueryHistoryNetFund(String accountCode, int maxNum, boolean sortDirect, AnswerHandler<TableData<IOPVAccount>> handler) throws IOException {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public int QueryHistoryNetFund(RequestPageData rpd, AnswerHandler<TableData<IOPVAccount>> handler) throws IOException {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public int QueryHistoryFundTransfer(String accountCode, int maxNum, boolean sortDirect, AnswerHandler<TableData<FundTransfer>> handler) throws IOException {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public int QueryHistoryFundTransfer(RequestPageData rpd, AnswerHandler<TableData<FundTransfer>> handler) throws IOException {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }


    @Override
    public int HSQLSelect(String hsql, AnswerHandler<TableData> handler) throws IOException {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public int SQLSelect(String sql, AnswerHandler<TableData> handler) throws IOException {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }
}
